﻿@model RH.Web.ViewModels.UtilityModels.ListConfig
@using RH.Web.Utility;
@using RH.Web.ViewModels
@{    
	String pageTitle = "Service Period List";
    ViewBag.Title = Html.GetPageTitle(pageTitle);
	String _EditUrlFormat = Url.PrivateUrl("Edit", "ServicePeriod") + "/{0}";
	///Bind ServicePeriod ListConfig
	///Following ListConfig binding needs to be edited according to the query result and need.
    RH.Web.ViewModels.UtilityModels.ListConfig _ListConfig = RH.Web.ViewModels.UtilityModels.ListConfigBuilder.Build(
        @"CompanyID {CompanyID}				
		, StartDate {StartDate}				
		, SpanDuration {SpanDuration}				
		, LeadPerSpan {LeadPerSpan}				
		, IsActive {IsActive}				
		, CreatedOn {CreatedOn}				
		"
        , null, _EditUrlFormat);//Model.DataSource, _EditUrlFormat); 
}
<div class="rh-page-heading">
    <h1>@pageTitle</h1>
    <div>
        Add/Edit and manage Service Period.
    </div>
</div>
<div class="rh-page-content">
    <div class="editor-field">
        @Html.DropDownList("CompanyID", BindSelectList.Builders())
    </div>
	<div class="panel panel-success">
        <div class="panel-heading">
            <div class="pull-left"><h4 id="h4">Service Period List</h4></div>
            <div class="pull-right"><a id="aAdd" class="btn btn-success disabled" href="#"><i class="glyphicon glyphicon-plus"></i> Add New Service Period</a></div>
            <div class="clearfix"></div>
        </div>
        <div class="panel-body" id="divResult">            
            
        </div>
    </div>
</div>

@*Delete Dialog Modal Start *@
<div class="modal fade" id="divDeleteModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" id="myModalLabel">Delete Service Span?</h4>
            </div>
            <div class="modal-body" id="deleteDialog-body">
                Do you really want to Delete this Service Span?
            </div>
            <div class="modal-footer">                
                <button type="button" class="btn btn-primary" onclick="DeleteSpan();"><i class="glyphicon glyphicon-ok"></i> Yes</button>
                <button type="button" class="btn btn-default" data-dismiss="modal"><i class="glyphicon glyphicon-remove"></i> No</button>
            </div>
        </div>
    </div>
</div>
@*Delete Dialog Modal End *@

@{
    ModalViewModel addModal = new ModalViewModel("divAddModal", String.Empty, String.Empty);
    addModal.IsLarge = true;
    addModal.BodyHtml = "<iframe id=\"iAdd\" scrolling=\"yes\" frameborder=\"0\" src=\"\" style=\"width:100%; height:500px;\"></iframe>";

    ModalViewModel editModal = new ModalViewModel("divEditModal", String.Empty, String.Empty);
    editModal.BodyHtml = "<iframe id=\"iEdit\" scrolling=\"yes\" frameborder=\"0\" src=\"\" style=\"width:100%; height:400px;\"></iframe>";

    ModalViewModel deleteConfirm = new ModalViewModel("deleteConfirm", "Confirm", String.Format("DeleteEntity('{0}', 'Service Period Span Deleted Successfully.', 'Sorry! we were not able to delete this Service Period Span.');", Url.AdminUrl("DeleteSpan", "ServicePeriod")));
    deleteConfirm.CloseButton = "No";
    deleteConfirm.SaveButton = "Yes";
}
@Html.Partial("_Modal", addModal)
@Html.Partial("_Modal", editModal)
@Html.Partial("_Modal", deleteConfirm)

@section JavaScriptPlaceHolder
{   
    <script type="text/javascript" language="javascript">
        var _DelCnfMsg = 'Are your sure, you want to delete this Service Period Span?';
    var _CompanyID = 0;
    $(document).ready(function () {
        var companyId = $('#CompanyID').val();
        if (companyId > 0)
            GetServicePeriods(companyId);
        $('#CompanyID').change(function () {
            GetServicePeriods($(this).val());
        });
        $('#aAdd').click(function (e) {
            e.preventDefault(); e.stopPropagation();
            $('#divAddModal').modal({ show: true });
            $('#divAddModal #iAdd').attr('src', '@Url.AdminUrl("Edit", "ServicePeriod")?CompanyId=' + _CompanyID);
            ShowLoadingAnimation(false);
        });
        $('#iAdd, #iEdit').load(function () { HideLoadingAnimation(); })
    });
    function GetServicePeriods(companyID) {
        ShowLoadingAnimation(false); _CompanyID = companyID;
        Ajax('@Url.AdminUrl("SpanList", "ServicePeriod")?companyID=' + companyID, null, function (result) {
            HideLoadingAnimation();
            $('#divResult').html(result);
            var msg = 'Service Period List';
            if (companyID > 0) {
                msg = 'Service Period List of <b>' + $('#CompanyID option:selected').html() + '</b>';
                $('#aAdd').removeClass('disabled');//.attr('href', '@Url.AdminUrl("Edit", "ServicePeriod")?companyId=' + companyID);
            }
            else
                $('#aAdd').addClass('disabled');
            $('#h4').html(msg);
        });
    }
    function ReloadSpanList() {
        GetServicePeriods(_CompanyID);
    }
    function EditSS(spanId, anchor) {
        //alert('EditSS' + spanId);
        $('#divEditModal').modal({ show: true });
        $('#divEditModal #iEdit').attr('src', '@Url.AdminUrl("EditSpan", "ServicePeriod")/' + spanId);
            ShowLoadingAnimation(false);
    }
        @*var _DeleteAnchor = null; _SpanID = 0;
        function DeleteConfirm(spanId, anchor) {
            _SpanID = spanId; _DeleteAnchor = anchor;
            $('#divDeleteModal').modal({ show: true });
        }
        function DeleteSpan() {            
            Ajax('@Url.AdminUrl("DeleteSpan", "ServicePeriod")/' + _SpanID, null, function (result) {
                if (result == 1) {
                    GetServicePeriods(_CompanyID);
                    $(_DeleteAnchor).closest('tr').remove();
                }
                else {

                }
            });
        }*@

    </script>
}

    


